Assignment Lab-2 Visulization of Data:¶

In this Lab-2 assignment we are trying to visulize the data using different python libraries such as Matplotlib, Seaborn, and Plotly.

Find More information from below...

  • Go to tutorial of Matplotlib.
  • Reference to Seaborn documentation.
  • Quick start Guide to Plotly

Lab-2 by OmPatel ID:8958837

image of Matplotlib

Implementation of Matplotlib:¶

Matplotlib is a comprehensive library in Python used for creating static, animated, and interactive visualizations in a wide range of formats. In the following cell we will plot the data "Generated using Mathematical formula" in 3D form. One simple chart is also generated.

In [1]:
%matplotlib notebook
In [2]:
import numpy as np
import matplotlib.pyplot as plt
plt.style.use('dark_background')

fig = plt.figure(figsize = (9,9))
ax = plt.axes(projection = '3d')
ax.grid()

t = np.arange(0, 10*np.pi, np.pi/50)
x = np.tan(t)
y = np.sin(t)

ax.plot3D(x,y,t)
ax.set_title('3D Plot')

# set axes label
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_zlabel('t')

plt.show()
In [3]:
import matplotlib.animation as animation

fig, ax = plt.subplots()
t = np.linspace(0, 3, 40)
g = -9.81
v0 = 12
z = g * t**2 / 2 + v0 * t

v02 = 5
z2 = g * t**2 / 2 + v02 * t

scat = ax.scatter(t[0], z[0], c="b", s=5, label=f'v0 = {v0} m/s')
line2 = ax.plot(t[0], z2[0], label=f'v0 = {v02} m/s')[0]
ax.set(xlim=[0, 3], ylim=[-4, 10], xlabel='Time [s]', ylabel='Z [m]')
ax.legend()


def update(frame):
    # for each frame, update the data stored on each artist.
    x = t[:frame]
    y = z[:frame]
    # update the scatter plot:
    data = np.stack([x, y]).T
    scat.set_offsets(data)
    # update the line plot:
    line2.set_xdata(t[:frame])
    line2.set_ydata(z2[:frame])
    return (scat, line2)


ani = animation.FuncAnimation(fig=fig, func=update, frames=40, interval=30)
plt.show()

Seaborn

Seaborn for Visualization:¶

Seaborn is a library for making statistical graphics in Python. It builds on top of matplotlib and integrates closely with pandas data structures.Seaborn helps you explore and understand your data. Its plotting functions operate on dataframes and arrays containing whole datasets and internally perform the necessary semantic mapping and statistical aggregation to produce informative plots.

We are using an in-build dataset called tips for this visualization program.

In [4]:
import seaborn as sns

sns.set_theme()
tips = sns.load_dataset("tips")
sns.catplot(data=tips, kind="violin", x="day", y="total_bill", hue="smoker", split=True)
Out[4]:
<seaborn.axisgrid.FacetGrid at 0x1c566c3c590>

Plotly Logo

Plotly as a Visualization tool:¶

Plotly's Python graphing library makes interactive, publication-quality graphs. Examples of how to make line plots, scatter plots, area charts, bar charts, error bars, box plots, histograms, heatmaps, subplots, multiple-axes, polar charts, and bubble charts. Plotly.py is free and open source and you can view the source code.

Following is a chart of Contour, which is a type of visialization used for Gradient descent.

In [5]:
import plotly.graph_objects as go
import plotly
plotly.offline.init_notebook_mode()

fig = go.Figure(data =
     go.Contour(
        z=[[10, 10.625, 12.5, 15.625, 20],
           [5.625, 6.25, 8.125, 11.25, 15.625],
           [2.5, 3.125, 5., 8.125, 12.5],
           [0.625, 1.25, 3.125, 6.25, 10.625],
           [0, 0.625, 2.5, 5.625, 10]],
        colorscale='Electric',
    ))
fig.show()

Now, Let's compare all three packages by making table.¶

Feature Matplotlib Seaborn Plotly
Ease of Use Versatile but requires more code for customization Designed for simplicity with concise syntax User-friendly with interactive features
Plot Types Supports a wide range of plot types Primarily focused on statistical plots Comprehensive support for various charts
Aesthetics Customization requires more effort Stylish default themes and color palettes Modern and aesthetically pleasing visuals
Default Styles Basic default styles More visually appealing default styles Modern and appealing default styles
Integration with Pandas Works well with Pandas data structures Seamlessly integrates with Pandas DataFrames Direct integration with Pandas DataFrames
Interactive Features Limited interactivity (can be enhanced with other libraries) Limited interactivity (focuses on static plots) Rich interactivity and dynamic visualizations
Documentation Extensive and well-documented Comprehensive documentation Detailed documentation with examples
Community Support Large and active community Growing community Active community and strong support
Backend Technology Built on NumPy arrays for data manipulation Extends Matplotlib and integrates with NumPy Utilizes JavaScript for interactive plots
Usage Widely used in diverse fields Often used for statistical data analysis Popular for web-based and interactive apps
In [6]:
!jupyter nbconvert --to html .\Lab2_OP_Vissulization.ipynb --output-dir ./docs/
'jupyter' is not recognized as an internal or external command,
operable program or batch file.
In [ ]: